home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / pctchnqs / 1990 / number6 / books.cpp next >
C/C++ Source or Header  |  1990-11-08  |  2KB  |  100 lines

  1. enum    _kindOfBook { SF, Fiction, Poetry };
  2.  
  3. //---------------------------------------------------------------
  4. class Book    {
  5.     private:
  6.        static int AllBooks,         // Total number of books
  7.              SFBooks,    // Number of SF books
  8.              FictionBooks,  // Number of Fiction books
  9.              PoetryBooks;    // Number of Poetry books
  10.  
  11.        enum _kindOfBook Kind;     // what kind of book this is
  12.  
  13.     public:
  14.         Book(enum _kindOfBook);
  15.         ~Book(void);
  16.         int numberOfBooks(void);
  17.         int numberOfSFBooks(void);
  18.         int numberOfFictionBooks(void);
  19.         int numberOfPoetryBooks(void);
  20.         int kind(void);        // what kind of book is this?
  21. };
  22.  
  23. //--------Book Kind---------
  24. // Return what kind of book this is
  25.  
  26. int Book::kind(void)
  27. {
  28.   return Kind;
  29. }
  30.  
  31. //-------Book Constructor
  32. // Build a new book of a particular kind.  Increment the
  33. // appropriate counters
  34.  
  35. Book::Book(enum _kindOfBook kind)
  36. {
  37.     switch(kind)    {
  38.         case SF:
  39.             SFBooks ++;
  40.             break;
  41.         case Fiction:
  42.             FictionBooks ++;
  43.             break;
  44.         case Poetry:
  45.             PoetryBooks ++;
  46.         default:
  47.             // ERROR
  48.             break;
  49.     }
  50.      Kind = kind;
  51.     AllBooks ++;
  52. }                
  53.  
  54. //--------Book Destructor------------
  55. //Destroy an instance of book; decrement the appropriate counter
  56.  
  57. Book::~Book(void)
  58. {
  59.     switch(Kind)    {
  60.         case SF:
  61.             SFBooks --;
  62.             break;
  63.         case Fiction:
  64.             FictionBooks --;
  65.             break;
  66.         case Poetry:
  67.             PoetryBooks --;
  68.             break;
  69.         default:
  70.             // ERROR
  71.             break;
  72.     }
  73.     AllBooks --;
  74. }
  75.  
  76. //---------Book numberOfBooks---------
  77. // Return the total number of books in the system
  78.  
  79. int Book::numberOfBooks(void)
  80. {
  81.     return(AllBooks);
  82. }
  83.  
  84. //--------Book numberOfSFBooks----------
  85. int Book::numberOfSFBooks(void)
  86. {
  87.     return(SFBooks);
  88. }
  89.  
  90. //--------Book numberOfFictionBooks----------
  91. int Book::numberOfFictionBooks(void)
  92. {
  93.     return(FictionBooks);
  94. }
  95.  
  96. //--------Book numberOfPoetryBooks------------
  97. int Book::numberOfPoetryBooks(void)
  98. {
  99.     return(PoetryBooks);
  100. }